#!/bin/bash

#------------------------------------------------------------------------------
#Filename:      84423-lvm.sh
#Version:       1.0
#Date:          2014/06/27
#Author:        xi.zhang
#Email:         xi.zhang@cs2c.com.cn
#Summary:       02.02系统管理功能-02逻辑卷管理-02字符命令-25将RAID逻辑卷的镜像数分离为单独的逻辑卷
#Notes:         分离Raid逻辑卷的镜像数
#Copyright:     China Standard Software Co.,Ltd.
#History:
#               Version 1.0,2014/06/27
#               -The first one
#               Version 1.1,2014/10/22
#               -The second one
#               -Add SFROOT
#               -Rename variables 

#------------------------------------------------------------------------------

if [ -z "$SFROOT" ]
then
    CMDLIB=./
    SFROOT=./
else
    CMDLIB=${SFROOT}/testcases/Management_Function
fi

. ${SFROOT}/lib/UserOps.sh
. ${CMDLIB}/lib/Partition_parted.sh
. ${CMDLIB}/lib/PV.sh
. ${CMDLIB}/lib/VG.sh
. ${CMDLIB}/lib/LV.sh

IsRoot
EchoResult "脚本执行用户为root"

export PVNUM=5
export VGNAME=vgroup-$$
export LVNAME=lvgroup-$$
export LVPATH=/dev/${VGNAME}/${LVNAME}
export LVSIZE=1
export NEWLV=newlv-$$

function CleanData()
{
  DeleteLV
  EchoInfo "Delete LV"

  EchoInfo "Delete VG"
  DeleteVG

  EchoInfo "Delete PV"
  DeletePV
}

trap CleanData INT EXIT

GetHarddisk

CreatePV
EchoResult "Step 1 :Create PV"

CreateVG
EchoResult "Step 2 :Create VG"

CreateRaid1LV
EchoResult "Step 3 :Create Raid1 LV"

#Display LV property
lvs -a -o name,copy_percent,devices ${VGNAME}
EchoResult "Step 4 :Display Raid LV property"

EchoInfo "sleep 60s to finish initialization..."
sleep 60

lvconvert --splitmirror 1 -n ${NEWLV}  ${VGNAME}/${LVNAME}
EchoResult "Step 5 :Modify Raid1 Mirror Number"

lvs -a -o name,copy_percent,devices ${VGNAME}
EchoResult "Step 6 :Display LV property"

lvremove -f ${VGNAME}/${NEWLV}
EchoResult "Step 7 :Remove new LV"
